import { ApidepartmentBunk, ApibedReservation } from "../../../api/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    select: {},
    time: "",
    btnLoading: false,
    startTime: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const t = new Date( new Date().getTime() + 1000 * 60 * 60 * 24 )
    const m = t.getMonth() + 1
    const d = t.getDate()
    const startTime = `${t.getFullYear()}-${m < 10 ? ('0' + m) : m }-${d < 10 ? ('0' + d) : d }`
    this.setData({
      startTime
    })
    this.getList()
  },

  getList() {
    ApidepartmentBunk().then(res => {
      this.setData({
        list: res.data
      })
    })
  },

  bindListSelect(e) {
    this.setData({
      select: this.data.list[e.detail.value]
    })
  },

  bindBirthChange(e) {
    this.setData({
      time: e.detail.value
    })
  },  

  onSubmit(e) {
    this.setData({
      btnLoading: true,
    })
    ApibedReservation({
      department_id: this.data.select.id,
      time: this.data.time
    }).then(res => {
      wx.showModal({
        title: "提示",
        content: "床位预约成功！",
        showCancel: false,
        confirmText: "确定",
        success:() => {
          wx.navigateBack()
        }
      })
    }).finally(_=>{
      this.setData({
        btnLoading: false,
      })
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})